class_name ControlView
extends BaseView

#region 属性
@export var action_scene:PackedScene
@export var v_box_container: VBoxContainer
@onready var restore_btn: Button = %RestoreBtn
var actions:Array[ControlViewAction] = []
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
func init_view():
	super.init_view()
func on_enter(args:Dictionary = {}):
	super.on_enter()
	var idx = 0
	for action in InputMap.get_actions().filter(func (x:String):return not x.begins_with("ui_")):
		var view_action:ControlViewAction = action_scene.instantiate() as ControlViewAction
		view_action.init_action(idx)
		idx += 1
		v_box_container.add_child(view_action)
		actions.append(view_action)
	_update_actions()
func on_pause(args:Dictionary = {}):
	super.on_pause()
func on_resume(args:Dictionary = {}):
	super.on_resume()
func on_exit(args:Dictionary = {}):
	super.on_exit()
func get_view_state() -> GameEnum.ViewState:
	return super.get_view_state()
#endregion
#region 公共方法
#endregion
#region 私有方法
func _update_actions():
	for action in actions:
		action.update_action()
func _restore_default_settings():
	InputMap.load_from_project_settings()
	_update_actions()
#endregion
#region 生命周期函数
func _ready() -> void:
	restore_btn.pressed.connect(_restore_default_settings)
#endregion
